﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Threading;
using System.Text.RegularExpressions;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Code.Models;
using Code.Commen;
using Code.BLL;


namespace QianBuo.Lottery.Server
{
    public class OutBill
    {
        public OutBill(Code.Models.Lottery lottery, Issue issue)
        {
            if (lottery == null)
                throw new ArgumentNullException("lottery");
            if (issue == null)
                throw new ArgumentNullException("issue");

            this.lottery = lottery;
            this.issue = issue;
        }
        private Code.Models.Lottery lottery;
        private Issue issue;
        private SchemeManage SM = new SchemeManage();

        /// <summary>
        /// 日志记录
        /// </summary>
        private log4net.ILog Log = Code.Commen.Log.GetLog(typeof(OutBill));

        public void Do()
        {
            var delaytime = CacheManage.OptionSite[Option_Site_Key.Site_Lottery_OutBill_Delay].ToDouble(0) * 60;
            int time = (int)(((issue.EndTime - DateTime.Now).TotalSeconds + delaytime) * 1000);
            if (time > 0)
                Thread.Sleep(time);
            try
            {
                SM.OutBill(issue.ID);
            }
            catch (Exception e)
            {
                if (Log.IsDebugEnabled)
                    Log.Debug(this.lottery.Alias + "出票出错", e);
                if (Log.IsInfoEnabled)
                    Log.Info(this.lottery.Alias + "出票出错:" + e.Message);
                if (Log.IsErrorEnabled)
                    Log.Error(this.lottery.Alias + "出票出错:" + e.Message);
            }
        }
    }
}
